package com.example.demo.TakeMaterial.controller;


import com.example.demo.TakeMaterial.dto.AddGood;
import com.example.demo.TakeMaterial.dto.RequisitionEditInfo;
import com.example.demo.TakeMaterial.entity.MaterialRequisition;
import com.example.demo.TakeMaterial.service.MaterialRequisitionService;
import com.example.demo.common.ResponseData;
import com.example.demo.entryWarehouse.dto.AcceptGood;
import com.example.demo.entryWarehouse.entity.AcceptGoods;
import com.example.demo.entryWarehouse.service.AcceptGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.awt.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangxuan
 * @since 2021-05-17
 */
@RestController
@RequestMapping("/TakeMaterial/material-requisition")
@PreAuthorize("hasAnyAuthority('1','2','4','5')")
@CrossOrigin(origins = {"*"})
public class MaterialRequisitionController {

@Autowired
    MaterialRequisitionService materialRequisitionService;


    //所有的领料记录
    @GetMapping("/selectAll")
    public ResponseData selectAll(){
        return materialRequisitionService.selectAll();
    }

    //加载未完成验收记录通过编号
    @GetMapping("/selectById")
    public ResponseData selectById(@RequestParam("requisitionId") String requisitionId){
        //System.out.println(requisitionId);
        return materialRequisitionService.selectById(requisitionId);
    }

    //更改验收信息
    @PostMapping("/editGood")
    public ResponseData editGood(@RequestBody MaterialRequisition materialRequisition){
        //System.out.println("edit");
        //System.out.println(materialRequisition);
        return  materialRequisitionService.editGood(materialRequisition);
    }

    //删除某验收物品
    @PostMapping("/RemoveGood")
    public ResponseData removeGood(@RequestParam("id") String id){
        //System.out.println(id);
        return materialRequisitionService.RemoveGood(id);
    }

    //验收物品
    @PostMapping("/insertGoods")
    public ResponseData insertGoods(@RequestBody AddGood addGood){
        System.out.println(addGood);
        return materialRequisitionService.insertGoods(addGood);
    }

    @GetMapping("/Select_AccId")
    public ResponseData Select_AccId(@RequestParam("acceptID")String acceptId){
        System.out.println(acceptId);
        return materialRequisitionService.Select_AccId(acceptId);
    }
    @GetMapping("/Select")
    public ResponseData Select(@RequestParam("department")String department,@RequestParam("provider")String provider){
        //System.out.println(acceptId);
        return materialRequisitionService.Select(department,provider);
    }
    //删除某验收物品
    @PostMapping("/removeMater")
    public ResponseData removeMater(@RequestParam("id") String id){
        System.out.println(id);
        return materialRequisitionService.removeMater(id);
    }

    //更改验收信息
    @PostMapping("/editMater")
    public ResponseData editMater(@RequestBody MaterialRequisition materialRequisition){
        System.out.println("edit");
        System.out.println(materialRequisition);
        return  materialRequisitionService.editMater(materialRequisition);
    }

    // 查找指定申请表状态的领料申请
    @GetMapping(value = "selectByHeaderStatus")
    public ResponseData selectByHeaderStatus(@RequestParam("status") String status) {
        return materialRequisitionService.selectByHeaderStatus(status);
    }

    // 出库时库管员编辑领料申请的实际数目和备注
    @PostMapping(value = "/deliveryEdit")
    public ResponseData deliveryEdit(@RequestBody RequisitionEditInfo updForm) {
        return materialRequisitionService.deliveryEdit(updForm);
    }

}

